/**
 * 行政区
 */
Ext.define('Admin.view.waterOptimum.resultshow.administrativeArea',{
	extend:'Ext.panel.Panel',
	xtype:'woAdministrativeArea',
	//起别名
	alias:'woAdministrativeArea',
	require:[],
	user:[],
	userCLs:'big-100 small-100',
	layout: {
        type: 'hbox',
        align: 'stretch'
    },
	items: [{
		/*html: '<div id="chart4-administartive-1" style="width:100%;height: 700px;"></div>',
		listeners: {
			resize: {
				fn: function(){
					administrativeMap.reflow();
				}
			},
			boxready: {
				fn: function(obj, width, height, eOpts){
					fillDataAdministrativeMap('chart4-administartive-1', '供水情况统计图（行政分区）');
				}
			}
		},*/
		xtype: 'image',
		region: 'center',
    	src: 'resources/images/wateroptimum/fhadmin.jpg',
    	flex: 1,
    	height: 700
    	/*html: '<div style="background-image:url("app/view/waterOptimum/fhadmin.jpg");width:100%;height:100%;"></div>',
    	flex: 1,
    	border: true*/
	},{
		xtype: 'grid',
		store: {xtype:'store',groupField: 'index1'},
		border: true,
		flex:1,
		margin: '0 0 0 15',
		features: [{
            id: 'group',
            ftype: 'groupingsummary',
            groupHeaderTpl: '行政区：{name}',
            hideGroupedHeader: true,
            enableGroupingMenu: false
        }],
		columns: [
			{ text: '水资源区', dataIndex: 'index2', minWidth: 100, width:'31%', align: 'center', summaryType: 'count', summaryRenderer: function(value, summaryData, dataIndex) {
                return '<span style="font-weight:bold;">合计</span>';
            } },
			{ text: '需水量(亿m³)', dataIndex: 'index3', minWidth: 100, width:'17%', align: 'center', summaryType: 'sum', renderer:
					function customRound(value, record){
						if(value == null)return null;
						return Ext.util.Format.round(value, 3);
					}, summaryRenderer: function(value, summaryData, dataIndex) {
		                return '<span style="font-weight:bold;">'+Ext.util.Format.round(value, 3)+'</span>';
		            }
			},
			{ text: '供水量(亿m³)', dataIndex: 'index4', minWidth: 100, width:'17%', align: 'center', summaryType: 'sum', renderer:
					function customRound(value, record){
						if(value == null)return null;
						return Ext.util.Format.round(value, 3);
					}, summaryRenderer: function(value, summaryData, dataIndex) {
		                return '<span style="font-weight:bold;">'+Ext.util.Format.round(value, 3)+'</span>';
		            }
			},
			{ text: '缺水量(亿m³)', dataIndex: 'index5', minWidth: 100, width:'17%', align: 'center', summaryType: 'sum', renderer:
					function customRound(value, record){
						if(value == null)return null;
						return Ext.util.Format.round(value, 3);
					}, summaryRenderer: function(value, summaryData, dataIndex) {
		                return '<span style="font-weight:bold;">'+Ext.util.Format.round(value, 3)+'</span>';
		            }
			},
			{ text: '缺水率', dataIndex: 'index6', minWidth: 100, width:'17%', align: 'center', summaryType: 'count', renderer:
					function customRound(value, record){
						if(value == null)return null;
						return Ext.util.Format.round(value, 3);
					}, summaryRenderer: function(value, summaryData, dataIndex) {
						var data = new Array();
						for(var key in summaryData){
							data.push(summaryData[key]);
						}
		                return '<span style="font-weight:bold;">'+(data[3]/data[1])+'</span>';
		            }
			}
		]
	}],
	administrativeMap: null,
	getStore: function(){
		return this.query('grid')[0].getStore();
	},
	displayData: function(data){
		this.getStore().setData(data);
	},
	fillDataAdministrativeMap: function(element, title){
		// 随机数据
		var data = [{name:"景德镇",value:71,value2:66},
			{"name":"萍乡","value":11,value2:Math.random().toFixed(2)},
			{"name":"新余","value":65,value2:Math.random().toFixed(2)},
			{"name":"鹰潭","value":92,value2:Math.random().toFixed(2)},
			{"name":"南昌","value":89,value2:Math.random().toFixed(2)},
			{"name":"吉安","value":100,value2:Math.random().toFixed(2)},
			{"name":"宜春","value":54,value2:Math.random().toFixed(2)},
			{"name":"上饶","value":10,value2:Math.random().toFixed(2)},
			{"name":"抚州","value":52,value2:Math.random().toFixed(2)},
			{"name":"赣州","value":6,value2:Math.random().toFixed(2)},
			{"name":"九江","value":18,value2:Math.random().toFixed(2)}];
		// 初始化图表
		this.administrativeMap = new Highcharts.Map(element, {
		  title: {
		    text: title
		  },
		  colorAxis: {
		    min: 0,
		    minColor: 'rgb(255,255,255)',
		    maxColor: '#006cee',
		    showInLegend: false
		  },
		  series: [{
		    data: data,
		    name: '随机数据',
		    mapData: Highcharts.maps['cn/jiangxi'],
		    joinBy: 'name', // 根据 name 属性进行关联,
		    	dataLabels: {
	                enabled: true,
	                format: '{point.name}'
	            }
		  }],
		  tooltip: {
	          useHTML: true,
	          headerFormat: '<table><tr><td>{point.name}</td></tr>',
	          pointFormat: '<tr><td>行政区</td><td>{point.properties.fullname}</td></tr>' +
	          '<tr><td>行政编号</td><td>{point.properties.areacode}</td></tr>' +
	          '<tr><td>缺水量</td><td>{point.value}</td></tr>' +
	          '<tr><td>缺水率</td><td>{point.value2}</td></tr>' ,
	          footerFormat: '</table>'
	      },
		});
	}
});
